package app;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.menhoo.toollibrary.common.assist.Check;
import com.example.menhoo.toollibrary.common.assist.Network;
import com.example.menhoo.toollibrary.common.helper.AndroidFileUtil;
import com.example.menhoo.toollibrary.common.helper.MessageUtil;
import com.example.menhoo.toollibrary.common.utils.HandlerUtil;
import com.example.menhoo.toollibrary.common.utils.NumberUtil;
import com.ksy.media.widget.ui.video.VideoMediaPlayerView;
import com.ksy.media.widget.util.PlayConfig;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.util.LogUtils;

import java.util.HashMap;
import java.util.Map;

import application.UIApplication;
import application.UIHttpURL;
import interfaces.IDownLoadListener;
import interfaces.IReturnObject;
import mainUI.AppActivity;
import menhoo.com.i8officelibrary.R;
import model.DownloadDbModel;
import model.FileInfo;
import model.ImageInfo;
import service.DownLoadService;
import tools.ToastUtil;
//http://sfvbook-eflake.bj.bcebos.com/BETA3/RYU/20151220224301.mp4

/**
 * 打开文件预览信息页面
 * Created by yanglei on 16/1/3.
 */

public class PreviewFileInfo extends AppActivity {

    private String VideoFormat = "mp4, flv, ts";
    private String MusicFormat = "aac, mp3";

    private ImageView imageViewFile;

    private TextView textViewProgress;

    private TextView textViewFileName;

    private TextView textViewFileDate;

    private TextView textViewFileSize;

    private ProgressBar progressBar;

    private Button btnDownload;

    private TableLayout tableLyout;

    private LinearLayout linearLayoutDownload;

    private LinearLayout linearLayoutInfo;

    private ImageButton imgBtnPlay;

    private VideoMediaPlayerView videoPlayerView;

    private LinearLayout linearLayoutVideo;

    private LinearLayout linearLayoutBtnPlay;

    private Button menu_btn_info;

    private FileInfo fileInfo = null;
    private ImageInfo imageInfo = null;

    private String suffix = null;

    boolean isError = false;

    int screenWidth = 0;
    int screenHeight = 0;
    /**
     * 根据手机的宽算出16:9的高
     */
    int videoMediaLayoutHeight16_9 = 0;
    int tempWidth = 0;

    private Button btnTest;
    private Button btnTest2;

    DownloadDbModel downloadDbModel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //
        setContentView(R.layout.preview_file_info);
        try{
            imageViewFile = (ImageView)findViewById(R.id.imageViewFile);
            textViewProgress = (TextView)findViewById(R.id.textViewProgress);
            textViewFileName = (TextView)findViewById(R.id.textViewFileName);
            textViewFileDate = (TextView)findViewById(R.id.textViewFileDate);
            textViewFileSize = (TextView)findViewById(R.id.textViewFileSize);
            progressBar = (ProgressBar)findViewById(R.id.progressBar);
            btnDownload = (Button)findViewById(R.id.btnDownload);
            tableLyout = (TableLayout)findViewById(R.id.tableLyout);
            linearLayoutDownload = (LinearLayout)findViewById(R.id.linearLayoutDownload);
            linearLayoutInfo = (LinearLayout)findViewById(R.id.linearLayoutInfo);
            imgBtnPlay = (ImageButton)findViewById(R.id.imgBtnPlay);
            videoPlayerView = (VideoMediaPlayerView)findViewById(R.id.videoPlayerView);
            linearLayoutVideo = (LinearLayout)findViewById(R.id.linearLayoutVideo);
            linearLayoutBtnPlay = (LinearLayout)findViewById(R.id.linearLayoutBtnPlay);
            btnTest = (Button)findViewById(R.id.btnTest);
            btnTest2 = (Button)findViewById(R.id.btnTest2);


            btnDownload.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String text = btnDownload.getText().toString();

                    if (text.equalsIgnoreCase(getString(R.string.download)) || text.equalsIgnoreCase(getString(R.string.download_go_on)) ||
                            text.equalsIgnoreCase(getString(R.string.retry))) {

                        addDownloadQueue(fileInfo.downloadTag, fileInfo.downloadUrl, UIApplication.getAppDownLoadPath
                                (PreviewFileInfo.this, fileInfo.downloadUrl), fileInfo.fileSize, new IReturnObject() {
                            @Override
                            public void returnResult(Object result) {
                                btnDownload.setText(R.string.wait);
                                btnDownload.setBackgroundResource(R.drawable.corners_gray_10dp);
                            }
                        });


                    } else if (text.equalsIgnoreCase(getString(R.string.open))) {
                        try {
                            String path = (String) v.getTag();
                            LogUtils.e("打开文件路径："+path);
                          //  ToastUtil.show(getApplicationContext() , path);
                            Intent it = AndroidFileUtil.openFile(path);
                            if (it != null) {
                                startActivity(it);
                            } else {
                                MessageUtil.showShortToast(PreviewFileInfo.this, "无法打开 " + AndroidFileUtil.getSuffix
                                        (path) + " 文件");
                            }

                        } catch (Exception e) {
                            LogUtils.e(e.getMessage() + "");
                        }
                    } else if (text.indexOf(getString(R.string.pause)) >= 0 || text.equalsIgnoreCase(getString(R.string.wait))) {
                        DownLoadService downLoadService = getDownLoadService();
                        if (downLoadService != null) {
                            downLoadService.cancelDownload(fileInfo.downloadUrl);
                            btnDownload.setText(R.string.wait);
                            btnDownload.setBackgroundResource(R.drawable.corners_gray_10dp);
                        }
                    }
                }
            });

            imgBtnPlay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (fileInfo != null && !Check.isEmpty(fileInfo.downloadUrl)) {

                        if (fileInfo != null && !Check.isEmpty(fileInfo.downloadTag)) {
                            DownloadDbModel downloadDbModel = UIApplication.getDownloadFileForTag(fileInfo.downloadTag);
                            if (downloadDbModel != null) {
                                startPlayer(downloadDbModel.path);
                            } else {
                                checkWifi(fileInfo.downloadUrl);
                            }
                        } else {
                            checkWifi(fileInfo.downloadUrl);
                        }
                    }
                }
            });


            btnTest.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int h = videoPlayerView.getVideoHeight();
                    int w = videoPlayerView.getVideoWidth();
                    //MessageUtil.showShortToast(this, "w=" + w + "::h=" + h);
                }
            });
            btnTest.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    videoPlayerView.setMovieRatio(100, 700);
                }
            });
        }
        catch (Exception e){
            LogUtils.e(e.getMessage()+"");
        }

        screenWidth = getResources().getDisplayMetrics().widthPixels;
        screenHeight = getResources().getDisplayMetrics().heightPixels;
        videoMediaLayoutHeight16_9 = ((int) (9f / 16f * screenWidth));

        try {
            fileInfo = (FileInfo) getIntent().getExtras().getSerializable("fileInfo");
            //判断文件后缀名,然后来初始化不同的view,如图片,视频,音乐3种
            if (fileInfo != null && !Check.isEmpty(fileInfo.fileName)) {

                setTitle(fileInfo.fileName);
                suffix = AndroidFileUtil.getSuffix(fileInfo.fileName);

                if (VideoFormat.indexOf(suffix) >= 0) {
                    changeView(ViewType.VideoInit);
                } else if (MusicFormat.indexOf(suffix) >= 0) {
                    changeView(ViewType.MusicInit);
                } else {
                    changeView(ViewType.ImageInit);
                }
            }

        } catch (Exception e) {
            MessageUtil.showShortToast(this, "打开文件详情失败");
        }
        try {
            imageInfo = (ImageInfo) getIntent().getExtras().getSerializable("imageInfo");
        } catch (Exception e) {
        }

        setDownLoadReceiverHandle(new IDownLoadListener() {
            @Override
            public void DownloadStart(Context context, Intent intent, String url, String tag) {
                if (fileInfo != null && tag.equals(fileInfo.downloadTag)) {
                    isError = false;
//                    progressBar.setVisibility(View.VISIBLE);
                    btnDownload.setBackgroundResource(R.drawable.selector_btn_red);
                    btnDownload.setText(R.string.pause);
                    try {
                        downloadDbModel = getDB().findFirst(Selector.from(DownloadDbModel.class).where("tag", "=", fileInfo
                                .downloadTag));
                        textViewProgress.setText(NumberUtil.getFileSize_KB_MB_GB(downloadDbModel.currDownloadSize) + " / " +
                                NumberUtil.getFileSize_KB_MB_GB(downloadDbModel.size));
                    } catch (Exception e) {
                        LogUtils.e(e.getMessage() + "");
                    }
                }

            }

            @Override
            public void DownloadLoading(Context context, Intent intent, String url, long total, long current, String tag) {
                if (fileInfo != null && tag.equals(fileInfo.downloadTag)) {
                    isError = false;
//                    progressBar.setVisibility(View.VISIBLE);
                    btnDownload.setBackgroundResource(R.drawable.selector_btn_red);
                    btnDownload.setText(getString(R.string.pause));
                    textViewProgress.setText(NumberUtil.getFileSize_KB_MB_GB(current) + " / " + NumberUtil.getFileSize_KB_MB_GB
                            (total));
                    progressBar.setMax((int) total);
                    progressBar.setProgress((int) current);
                }

            }

            @Override
            public void DownloadFinish(Context context, Intent intent, String url, String filePath, String tag) {
                if (fileInfo != null && tag.equals(fileInfo.downloadTag)) {
                    isError = false;
                    progressBar.setVisibility(View.INVISIBLE);
                    btnDownload.setBackgroundResource(R.drawable.selector_btn_green);
                    btnDownload.setText(R.string.open);
                    btnDownload.setTag(filePath);
                }

            }

            @Override
            public void DownloadCancelled(Context context, Intent intent, String url, String tag) {
                if (fileInfo != null && tag.equals(fileInfo.downloadTag)) {

                    if (!isError && fileInfo != null && !Check.isEmpty(fileInfo.downloadTag)) {
                        DownloadDbModel downloadDbModel = UIApplication.getDownloadFileForTag(tag);
                        if (downloadDbModel != null) {
                            progressBar.setVisibility(View.INVISIBLE);
                            btnDownload.setBackgroundResource(R.drawable.selector_btn_green);
                            btnDownload.setText(R.string.open);
                            btnDownload.setTag(downloadDbModel.path);
                        } else {
                            btnDownload.setBackgroundResource(R.drawable.selector_btn_blue);
                            btnDownload.setText(R.string.download_go_on);
                        }
                    }
                }

            }

            @Override
            public void DownloadError(Context context, Intent intent, String url, String errorMsg, String tag) {
                if (fileInfo != null && tag.equals(fileInfo.downloadTag)) {
                    isError = true;
                    btnDownload.setBackgroundResource(R.drawable.selector_btn_red);
                    btnDownload.setText(R.string.retry);
                    if (errorMsg.equals(DownLoadService.ONLY_WIFI_DOWNLOAD)) {
                        MessageUtil.showShortToast(PreviewFileInfo.this, "只能wifi下载");
                    }

                }
            }
        });

        initData();
    }

    @Override
    public void onNetworkStateChange(Context context, Intent intent, boolean isWifi, boolean isNetworkAvailable, String message) {
        super.onNetworkStateChange(context, intent, isWifi, isNetworkAvailable, message);
        if (videoPlayerView.getMediaPlayerVideoView().isPlaying() && !isWifi) {
            videoPlayerView.getMediaPlayerVideoView().pause();
            MessageUtil.showLongToast(this, "当前是 2G/3G 网络,浏览在线视频将消化大量流量");
        }
    }

    void setMovieRatioLayoutH(int H) {
        //得到视频文件的宽和高
        int r_w = videoPlayerView.getVideoWidth();
        int r_h = videoPlayerView.getVideoHeight();
        //得到比例
        float r_ratio = r_w / 1.0f / r_h;
//        MessageUtil.showShortToast(PreviewFileInfo.this,"r_w:"+r_w+"==r_h:"+r_h);
        videoPlayerView.setMovieRatio(((int) (H * r_ratio)), H);
    }

    void setLinearLayoutVideo(int w, int h) {
        ViewGroup.LayoutParams layoutParams = linearLayoutVideo.getLayoutParams();
        layoutParams.width = w;
        layoutParams.height = h;
        linearLayoutVideo.setLayoutParams(layoutParams);
    }

    @Override
    protected void onResume() {
        super.onResume();
        videoPlayerView.onResume();
        if (fileInfo != null && !Check.isEmpty(fileInfo.downloadTag)) {
            try {
                downloadDbModel = getDB().findFirst(Selector.from(DownloadDbModel.class).where("url", "=", fileInfo.downloadUrl));
                if (downloadDbModel != null) {
                    if (downloadDbModel.isComplete) {
                        btnDownload.setBackgroundResource(R.drawable.selector_btn_green);
                        btnDownload.setText(R.string.open);
                        btnDownload.setTag(downloadDbModel.path);
                    } else {
                        btnDownload.setBackgroundResource(R.drawable.selector_btn_blue);
                        btnDownload.setText(R.string.download_go_on);
                        textViewProgress.setText(NumberUtil.getFileSize_KB_MB_GB(downloadDbModel.currDownloadSize) + " / " +
                                NumberUtil.getFileSize_KB_MB_GB(downloadDbModel.size));
                    }

                }
            } catch (Exception e) {
                LogUtils.e(e.getMessage() + "");
            }

        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        videoPlayerView.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        videoPlayerView.onDestroy();
//        MessageUtil.showShortToast(this,"videoPlayerView ....onDestroy()......");
    }

    /**
     * 视频开始播放url
     *
     * @param url
     */
    void startPlayer(String url) {
        videoPlayerView.play(checkURL(url));
        changeView(ViewType.VideoPlaying);
//        videoPlayerView.play("http://sm.domob.cn/ugc/151397.mp4");
//        MessageUtil.showShortToast(this, "videoPlayerView play url = " + url);
    }

    public FileInfo getFileInfo() {
        return fileInfo;
    }

    public ImageInfo getImageInfo() {
        return imageInfo;
    }

    void initData() {

        if (!Check.isEmpty(fileInfo.fileName)) {
            textViewFileName.setText(fileInfo.fileName);
        }

        if (!Check.isEmpty(fileInfo.fileSize)) {
            textViewFileSize.setText(fileInfo.fileSize);
        } else {
            textViewFileSize.setVisibility(View.GONE);
        }

        if (!Check.isEmpty(fileInfo.fileDate)) {
            textViewFileDate.setText(fileInfo.fileDate);
        } else {
            textViewFileDate.setVisibility(View.GONE);
        }

        if (!Check.isEmpty(fileInfo.downloadUrl)) {
            btnDownload.setText(R.string.download);
            btnDownload.setEnabled(true);
        } else {

            btnDownload.setText("无法下载");
            btnDownload.setEnabled(false);
        }
        if (fileInfo.downloadTag==null){
            fileInfo.downloadTag = fileInfo.fileName;
        }
        //metadata
        if (fileInfo.metadata != null && fileInfo.metadata.size() > 0) {
            for (String key : fileInfo.metadata.keySet()) {
                String val = fileInfo.metadata.get(key);
                tableLyout.addView(createMetadataView(key, val));
            }
        }

        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams
                .MATCH_PARENT);

        tableLyout.addView(createMetadataView("文件大小", fileInfo.fileSize), params);
        tableLyout.addView(createMetadataView("创建时间", fileInfo.fileDate), params);
    }

    /**
     * 根据元数据创建view
     *
     * @param key
     * @param Val
     * @return
     */
    View createMetadataView(String key, String Val) {
        View tableRow = getLayoutInflater().inflate(R.layout.preview_file_info_item, null);
        TextView textViewKey = (TextView) tableRow.findViewById(R.id.textViewKey);
        TextView textViewVal = (TextView) tableRow.findViewById(R.id.textViewVal);

        textViewKey.setText(key);
        textViewVal.setText(Val);

        return tableRow;
    }



    void checkWifi(final String url) {
        if (Network.isWifi(this)) {
            startPlayer(url);
        } else {
            showSimpleDialogMessage("当前是 2G/3G 网络,浏览在线视频将消化大量流量,确定要播放此视频么?", new IReturnObject() {
                @Override
                public void returnResult(Object result) {
                    startPlayer(url);
                }
            }, false, true);
        }
    }

    /**
     * 打开预览文件(有缩略图)
     */
    void openFile() {
        if (fileInfo != null && !Check.isEmpty(fileInfo.fileName)) {
            Intent it = null;

            if (suffix.equalsIgnoreCase("3gp") || suffix.equalsIgnoreCase("mp4")) {
                MessageUtil.showShortToast(this, "视频");
            } else if (suffix.equals("m4a") || suffix.equals("mid") ||
                    suffix.equals("xmf") || suffix.equals("ogg") || suffix.equals("wav") || suffix.equals("mp3")) {
                MessageUtil.showShortToast(this, "音乐");
            } else if (suffix.equalsIgnoreCase("ppt") || suffix.equalsIgnoreCase("pptx")) {
                it = new Intent(PreviewFileInfo.this, ScaleImage.class);// 创建Intent对象
            } else if (suffix.equalsIgnoreCase("doc") || suffix.equalsIgnoreCase("docx")) {
                it = new Intent(PreviewFileInfo.this, ScaleDocImage.class);// 创建Intent对象
            } else {
                it = new Intent(PreviewFileInfo.this, ScaleImage.class);// 创建Intent对象
            }

            if (it != null) {
                //imgInfo
                it.putExtra("imageInfo", getImageInfo());
                //fileInfo
                it.putExtra("fileInfo", getFileInfo());
                startActivity(it);
                overridePendingTransition(com.example.menhoo.menhoolibrary.R.anim.anim_scale_in, com.example.menhoo
                        .menhoolibrary.R
                        .anim.anim_scale_out);
                onBackPressed();
            }

        }
    }

    /**
     * 变换布局根据type
     *
     * @param type
     */
    void changeView(ViewType type) {
        switch (type) {
            case MusicInit:
                imageViewFile.setVisibility(View.GONE);
                linearLayoutBtnPlay.setVisibility(View.VISIBLE);
                videoPlayerView.setVisibility(View.VISIBLE);
                videoPlayerView.showMusicLayout();
                initVideoPlayerView();

                break;
            case MusicPlaying:
                imageViewFile.setVisibility(View.GONE);
                linearLayoutBtnPlay.setVisibility(View.GONE);
                videoPlayerView.setVisibility(View.VISIBLE);
                break;
            case VideoInit:
                imageViewFile.setVisibility(View.GONE);
                linearLayoutBtnPlay.setVisibility(View.VISIBLE);
                videoPlayerView.setVisibility(View.VISIBLE);
                videoPlayerView.hideMusicLayout();
                initVideoPlayerView();
                break;
            case VideoPlaying:
                imageViewFile.setVisibility(View.GONE);
                linearLayoutBtnPlay.setVisibility(View.GONE);
                videoPlayerView.setVisibility(View.VISIBLE);
                break;
            default://imageView
                imageViewFile.setVisibility(View.VISIBLE);
                linearLayoutBtnPlay.setVisibility(View.GONE);
                videoPlayerView.setVisibility(View.GONE);

                //
                if (!Check.isEmpty(fileInfo.thumbUrl)) {
                    getBitmapLoader().display(imageViewFile, fileInfo.thumbUrl, new BitmapLoadCallBack<ImageView>() {
                        @Override
                        public void onLoadCompleted(ImageView imageView, String s, Bitmap bitmap, BitmapDisplayConfig
                                bitmapDisplayConfig,
                                                    BitmapLoadFrom bitmapLoadFrom) {
                            if (bitmap != null && bitmap.getHeight() > 1 && bitmap.getWidth() > 1) {
                                imageView.setImageBitmap(bitmap);
                                //
                                setCustomRightButton(R.layout.menu_info);
                                menu_btn_info = (Button) findViewById(R.id.menu_btn_info);
                                menu_btn_info.setText("预览");
                                menu_btn_info.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        openFile();
                                    }
                                });
                                imageView.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        openFile();
                                    }
                                });
                            } else {
                                imageView.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(suffix));
                            }
                        }

                        @Override
                        public void onLoadFailed(ImageView imageView, String s, Drawable drawable) {
                            imageView.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(suffix));
                        }
                    });
                } else {
                    imageViewFile.setImageResource(AndroidFileUtil.getFileIconRIDFileExt(suffix));
                }

                break;
        }
    }

    void initVideoPlayerView() {
        //
        videoPlayerView.setTitle(fileInfo.fileName);
        videoPlayerView.getMediaPlayerEventActionView().hideTitle();
        videoPlayerView.setPlayConfig(false, PlayConfig.INTERRUPT_MODE_PAUSE_RESUME);
        //设置初始16:9的屏幕比例
        setLinearLayoutVideo(screenWidth, videoMediaLayoutHeight16_9);
        //
        videoPlayerView.setPlayerViewCallback(new VideoMediaPlayerView.PlayerViewCallback() {
            @Override
            public void hideViews() {
                setTitleDisplay(false);
                videoPlayerView.getMediaPlayerEventActionView().showTitle();
                linearLayoutInfo.setVisibility(View.GONE);
                linearLayoutDownload.setVisibility(View.GONE);
                //全屏
                setLinearLayoutVideo(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                setMovieRatioLayoutH(screenWidth - getStatusBarHeight(PreviewFileInfo.this));
            }

            @Override
            public void restoreViews() {
                setTitleDisplay(true);
                videoPlayerView.getMediaPlayerEventActionView().hideTitle();
                linearLayoutInfo.setVisibility(View.VISIBLE);
                linearLayoutDownload.setVisibility(View.VISIBLE);

                setLinearLayoutVideo(screenWidth, videoMediaLayoutHeight16_9);
                setMovieRatioLayoutH(videoMediaLayoutHeight16_9);
            }

            @Override
            public void onPrepared() {
                tempWidth = videoPlayerView.getVideoWidth();
                setMovieRatioLayoutH(videoMediaLayoutHeight16_9);
                HandlerUtil.runOnUiThreadDelay(new Runnable() {
                    @Override
                    public void run() {
                        setMovieRatioLayoutH(videoMediaLayoutHeight16_9);
                    }
                }, 500);

            }

            @Override
            public void onQualityChanged() {
                MessageUtil.showShortToast(PreviewFileInfo.this, "onQualityChanged");
            }

            @Override
            public void onFinish(int playMode) {
                MessageUtil.showShortToast(PreviewFileInfo.this, "onFinish");
            }

            @Override
            public void onError(int errorCode, String errorMsg) {
                MessageUtil.showShortToast(PreviewFileInfo.this, "onError");
            }
        });

    }

    enum ViewType {
        /**
         * 图片
         */
        ImageInit,
        /**
         * 视频还没有播放,显示一个播放按钮
         */
        VideoInit,
        /**
         * 视频播放中
         */
        VideoPlaying,
        /**
         * 音频还没有播放,显示一个播放按钮
         */
        MusicInit,
        /**
         * 音频播放中
         */
        MusicPlaying
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(com.example.menhoo.menhoolibrary.R.anim.anim_scale_in, com.example.menhoo.menhoolibrary.R
                .anim.anim_scale_out);
    }
    /**
     * 加工url 相对路径加http+网站,没有session的家__session__
     */
    String checkURL(String url) {
        if (Check.isEmpty(url)) {
            return null;
        }
        String fullURL = UIHttpURL.getWebSiteFullUrl(url);
        Map<String, String> parameters = UIHttpURL.getUrlParameters(fullURL);
        if (parameters==null || !parameters.containsKey("__session__")) {
            Map<String, String> map = new HashMap();
            map.put("__session__", UIApplication.getSession());
            return UIHttpURL.getWebSiteFullUrl(url, map);
        }
        return fullURL;
    }

}
